﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Server.ActivityFeed;
using System.Reflection;

namespace ESF.SharePoint.Utility
{
    static class ActivityEventExtension
    {
        

        //public static ActivityManager GetActivityManager(this ActivityEvent activityEvent)
        //{
        //    Type type = typeof(ActivityEvent);
        //    FieldInfo field = type.GetField("m_objManager", BindingFlags.NonPublic | BindingFlags.Instance);
        //    return (ActivityManager)field.GetValue(activityEvent);
        //}

        //public static Entity GetOwner(this ActivityEvent activityEvent)
        //{
        //    Entity owner = activityEvent.Owner;
        //    if (owner == null)
        //    {
        //        // Required because sometimes previous object is null. This fix calling explicit method
        //        ActivityTemplateVariable atv = activityEvent.GetATV();
        //        owner =  atv.Owner;
        //    }
        //    return owner;
        //}

        public static ActivityTemplateVariable GetATV(this ActivityEvent activityEvent)
        {
            Type type = typeof(ActivityEvent);
            PropertyInfo propertyATV = type.GetProperty("ATV", BindingFlags.NonPublic | BindingFlags.Instance);
            ActivityTemplateVariable atv = (ActivityTemplateVariable)propertyATV.GetValue(activityEvent, null);
            return atv;
        }

        //public static Entity GetPublisher(this ActivityEvent activityEvent)
        //{
        //    Entity publisher = activityEvent.Publisher;
        //    if (publisher == null)
        //    {
        //        // Required because sometimes previous object is null. This fix calling explicit method
        //        ActivityTemplateVariable atv = activityEvent.GetATV();
        //        publisher = atv.Publisher;
        //    }
        //    return publisher;
        //}

        public static void ForceLoad(this ActivityEvent activityEvent)
        {
            List<Link> links = activityEvent.LinksList;
        }

    }
}
